<template>
  <div class="icons">
    <swiper>
      <!-- slides -->
      <swiper-slide v-for="(list1,index) of pages" :key="index">
        <div class="icon" v-for="list of list1" :key="list.id">
          <div class="icon-img"> <img :src="list.url" alt="" class="img-a"></div>
          <p>{{list.disc}}</p>
        </div>
      </swiper-slide>

    </swiper>

  </div>
</template>
<script>
export default {
  data() {
    return {
      iconli: [
        {
          id: "0001",
          url:
            "http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png",
          disc: "滑雪季"
        },
        {
          id: "0002",
          url:
            "http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png",
          disc: "滑雪季1"
        },
        {
          id: "0003",
          url:
            "http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png",
          disc: "滑雪季2"
        },
        {
          id: "0004",
          url:
            "http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png",
          disc: "滑雪季3"
        },
        {
          id: "0005",
          url:
            "http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png",
          disc: "滑雪季4"
        },
        {
          id: "0006",
          url:
            "http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png",
          disc: "滑雪季5"
        },
        {
          id: "0007",
          url:
            "http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png",
          disc: "滑雪季6"
        },
        {
          id: "0008",
          url:
            "http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png",
          disc: "滑雪季7"
        },
        {
          id: "0009",
          url:
            "http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png",
          disc: "滑雪季8"
        }
      ]
    };
  },
  computed: {
    pages() {
      const pages = [];
      this.iconli.forEach((item, index) => {
        //math.floor是向下取整，找到去掉小数部分
        // console.log(index);
        const page = Math.floor(index / 8);
        //如果不为空才在当前数组中去创建一个数组
        if (!pages[page]) {
          pages[page] = [];
        }
        //把遍历的值压入数组,由于数组中的page是会变化的，所以会创建出两个数组，并且把八倍数的值压缩第二个数组形成二维数组
        pages[page].push(item);
      });
      //返回的是二维数组
      return pages;
    }
  }
};
</script>
<style lang="stylus" scoped>
.icons >>> .swiper-container {
  height: 0;
  padding-bottom: 50%;
}

.icons {
  overflow: hidden;
  height: 0;
  padding-bottom: 50%;
}

.icon {
  float: left;
  width: 25%;
  height: 0;
  padding-bottom: 25%;
  overflow: hidden;
  position: relative;
  text-align: center;
}

.icon-img {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0.44rem;
  box-sizing: border-box;
  padding: 5px;
}

.img-a {
  height: 100%;
}

.icon p {
  position: absolute;
  bottom: 0.44rem;
  left: 0;
  right: 0;
  bottom: 0.1rem;
  text-align: center;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
</style>

